package com.zjh;

import com.zjh.bean.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * @author LiZiQiu
 * @data 2023/3/1
 */
public class Test3 {
    public static void main(String[] args) {
        try {
            Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory build = builder.build(reader,"a2");
            SqlSession session = build.openSession();
            Student student = new Student();
            student.setId(5);
            student.setStudentno("stu005");
            student.setName("小旺");
            int i = session.insert("com.zjh.dao.StudentDao.insertStudent",student);
            session.commit();
            System.out.println(i);
            session.close();
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
